package yz.cp.back.s.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import yz.cp.back.s.entity.SysDepartmentHeader;
import yz.cp.back.s.mapper.SysDepartmentHeaderMapper;
import yz.cp.back.s.service.ISysDepartmentHeaderService;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-04-03
 */
@Service
public class SysDepartmentHeaderServiceImpl extends ServiceImpl<SysDepartmentHeaderMapper, SysDepartmentHeader> implements ISysDepartmentHeaderService {
    @Override
    public List<String> findHeaderByDepartmentId(String departmentId, Integer type) {

        List<String> list = new ArrayList<>();
        List<SysDepartmentHeader> headers = list(new QueryWrapper<SysDepartmentHeader>()
                .lambda().eq(SysDepartmentHeader::getDepartmentId,departmentId)
                .eq(SysDepartmentHeader::getType, type));
        headers.forEach(e->
            list.add(e.getUserId())
        );
        return list;
    }

    @Override
    public void deleteByDepartmentId(String departmentId) {
        remove(new QueryWrapper<SysDepartmentHeader>().lambda().eq(SysDepartmentHeader::getDepartmentId,departmentId)); }

    @Override
    public void deleteByUserId(String userId) {
        remove(new QueryWrapper<SysDepartmentHeader>().lambda().eq(SysDepartmentHeader::getUserId,userId));
    }
}
